//
//  BIDLoadWebPageViewController.m
//  HJGJCommunity
//
//  Created by mal on 2017/5/20.
//  Copyright © 2017年 mal. All rights reserved.
//

#import "BIDLoadWebPageViewController.h"

@interface BIDLoadWebPageViewController ()<UIWebViewDelegate>

@end

@implementation BIDLoadWebPageViewController
@synthesize requestURL;
@synthesize webURL;
@synthesize webContent;
@synthesize externalContent;

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.title = @"详情";
    self.navigationController.navigationBarHidden = NO;
    [self.view setBackgroundColor:[UIColor whiteColor]];
    [_webView setBackgroundColor:[UIColor clearColor]];
    [_webView setOpaque:YES];
    if(requestURL)
    {
        [self loadData];
    }
    else if(webURL)
    {
        NSURL *url = [NSURL URLWithString:webURL];
        NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
        [_webView loadRequest:urlRequest];
    }
    else if(webContent)
    {
        [self showWebContent:webContent];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)loadData
{
}

- (void)showWebContent:(NSString *)content
{
    NSMutableString *strContent = [NSMutableString string];
    if(externalContent)
    {
        [strContent appendString:externalContent];
    }
    NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[content dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
    [strContent appendString:attrStr.string];
    [_webView loadHTMLString:strContent baseURL:nil];
}

#pragma mark - UIWebViewDelegate
- (void)webViewDidStartLoad:(UIWebView *)webView
{
    NSLog(@"start load");
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    NSLog(@"finish load");
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
    NSLog(@"%@", [error localizedDescription]);
}

@end
